#ifndef __BSP_CONFIG_H
#define __BSP_CONFIG_H

#ifdef __cplusplus
extern "C"
{
#endif

#include "es_oled.h"
#include "es_uart.h"
#include <rtthread.h>

struct rt_ringbuffer
{
    rt_uint8_t *buffer_ptr;

    rt_uint16_t read_mirror : 1;
    rt_uint16_t read_index : 15;
    rt_uint16_t write_mirror : 1;
    rt_uint16_t write_index : 15;

    rt_int16_t buffer_size;
};

enum rt_ringbuffer_state
{
    RT_RINGBUFFER_EMPTY,
    RT_RINGBUFFER_FULL,
    /* half full is neither full nor empty */
    RT_RINGBUFFER_HALFFULL,
};

#define rt_ringbuffer_space_len(rb) ((rb)->buffer_size - rt_ringbuffer_data_len(rb))

// <<< Use Configuration Wizard in Context Menu >>>
	
/* 使用 kt_printf() 输出调试信息 */
// <c1>USING_OLED_DEBUG
// <i> USING_OLED_DEBUG
#define USING_OLED_DEBUG
// </c>

// <e> USING_SERIAL_DEBUG
// <i> USING_SERIAL_DEBUG
#define USING_SERIAL_DEBUG		1

#if 		USING_SERIAL_DEBUG == 0
#undef USING_SERIAL_DEBUG
#endif

#ifdef	USING_SERIAL_DEBUG
/* 配置 kt_printf() 占用的串口及其波特率 */
// <o>DEBUG_USART
//  <i>Default: USART2
//	<0x40013800=> USART1
//	<0x40004400=> USART2
//	<0x40004800=> USART3
#define DEBUG_USARTx	((USART_TypeDef *)0x40013800)

// <o>USART_BAUDRATE
//  <i>Default: 115200
//	<600-460800>
#define DEBUG_USART_BAUDRATE 115200

// <e> FINSGH_USING_INTERRUPT
// <i> FINSGH_USING_INTERRUPT
#define FINSGH_USING_INTERRUPT		1

#if 		FINSGH_USING_INTERRUPT == 0
#undef FINSGH_USING_INTERRUPT
#endif

#ifdef	FINSGH_USING_INTERRUPT

// <o>UART_RX_BUF_LEN
//  <i>Default: 16
//	<4-64>
#define UART_RX_BUF_LEN 16
#endif
//</e>

//</e>
#endif


// <<< end of configuration section >>>

void rt_ringbuffer_init(struct rt_ringbuffer *rb,
                        rt_uint8_t           *pool,
                        rt_int16_t            size);

void getchar_irq_init(void);
void DEBUG_USART_IRQHandler(void);

#ifdef __cplusplus
}
#endif

#endif /* __BSP_CONFIG_H */
